<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<script>

import {userInfo} from "@/api/user";
import {getCartCount} from "@/api/product";

export default {
  name: 'App',
  components: {
  },
  mounted(){
    if(this.$cookies.get('id')){
      this.getUser();
      this.getCartCount();
    }
  },
  methods:{
    getUser(){
      userInfo().then(res => {
        this.$cookies.set("id", res.id)
        this.$store.dispatch("saveUserName", res.username)
      }).catch(function () {
      })
    },
    getCartCount(){
      getCartCount().then((res=0) => {
        this.$store.dispatch('saveCartCount',res);
      }).catch(function () {
      })
    }
  }
}
</script>

<style>
</style>
